package com.jch.string_encoder;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.StandardCharsets;

public class DemoChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 基于换行符
        ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
        // String解码器
        ch.pipeline().addLast(new StringDecoder(StandardCharsets.UTF_8));
        // String编码器
        ch.pipeline().addLast(new StringEncoder(StandardCharsets.UTF_8));
        // 自定义处理器
        ch.pipeline().addLast(new DemoServerHandler());
    }
}
